Vue.component('update', {
    template: `
		<el-dialog title="修改" width="600px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
			    <el-row >
					<el-col :span="24">
						<el-form-item label="活动分类" prop="language">
							<el-select style="width:100%" v-model="form.language" filterable clearable placeholder="请选择语言">
								<el-option v-for="(item,i) in language_list" :key="i" :label="item.name" :value="item.id"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="分类标题" prop="title">
							<el-input  v-model="form.title" autoComplete="off" clearable  placeholder="请输入用户名"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="作者LOGO" prop="pic">
							<Upload v-if="show" size="small" file_type="image" :image.sync="form.author_logo"></Upload>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="作者" prop="author">
							<el-input  v-model="form.author" autoComplete="off" clearable  placeholder="请输入分类标题"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="活动分类" prop="cid">
							<el-select style="width:100%" v-model="form.cid" filterable clearable placeholder="请选择所属分类">
								<el-option v-for="(item,i) in charitable_class" :key="i" :label="item.title" :value="item.id"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="分类图片" prop="pic">
							<Upload v-if="show" size="small" file_type="image" :image.sync="form.pic"></Upload>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="内容" prop="content">
							<wang-editor v-if="show" :is_clear="is_clear" :wangcontent.sync="form.content"></wang-editor>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`,
    components:{
    },
    props: {
        show: {
            type: Boolean,
            default: false
        },
        size: {
            type: String,
            default: 'small'
        },
        info: {
            type: Object,
        },
    },
    data(){
        return {
            form: {
                language:'',
                title:'',
                author:'',
                author_logo:'',
                cid:'',
                pic:'',
                content:'',
            },
            loading:false,
            is_clear:false,
            charitable_class:[],
            language_list:[{'id':1,'name':'简体'},{'id':2,'name':'繁體'},{'id':3,'name':'English'}],
            rules: {
                language:[
                    {required: true, message: '请选择语言', trigger: 'blur'},
                ],
                title:[
                    {required: true, message: '请输入标题', trigger: 'blur'},
                ],
                author:[
                    {required: true, message: '请输入作者名', trigger: 'blur'},
                ],
                cid:[
                    {required: true, message: '请选择分类', trigger: 'blur'},
                ],
            }
        }
    },
    watch:{
        show(val){
            if(val){
                axios.post(base_url + '/Charitable/class_list').then(res => {
                    if(res.data.status == 200){
                        this.charitable_class = res.data.data
                    }
                })
            }
        }
    },
    methods: {
        open(){
            this.form = this.info
            this.form.create_time = parseTime(this.form.create_time)
        },
        submit(){
            this.$refs['form'].validate(valid => {
                if(valid) {
                    this.loading = true
                    axios.post(base_url + '/Charitable/article_edit',this.form).then(res => {
                        if(res.data.status == 200){
                            this.$message({message: res.data.msg, type: 'success'})
                            this.$emit('refesh_list')
                            this.closeForm()
                        }else{
                            this.loading = false
                            this.$message.error(res.data.msg)
                        }
                    }).catch(()=>{
                        this.loading = false
                    })
                }
            })
        },
        closeForm(){
            this.$emit('update:show', false)
            this.loading = false
            if (this.$refs['form']!==undefined) {
                this.$refs['form'].resetFields()
            }
        },
    }
})
